using Castle.ActiveRecord;
using WCell.Constants.Spells;

namespace WCell.RealmServer.Database
{
	[ActiveRecord(Access = PropertyAccess.Property)]
	public class SpellRecord : ActiveRecordBase<SpellRecord>
	{
		[Field("SpellId", NotNull = true, Access = PropertyAccess.FieldCamelcase)]
		private long _spellId;

		[PrimaryKey(PrimaryKeyType.Native, "SpellRecordId")]
		public long RecordId
		{
			get;
			set;
		}

		[Property(NotNull = true)]
		public long OwnerId
		{
			get;
			set;
		}

		public bool New
		{
			get;
			internal set;
		}

		public uint SpellId
		{
			get
			{
				return (uint)_spellId;
			}
			set
			{
				_spellId = value;
			}
		}

		public override void SaveAndFlush()
		{
			base.SaveAndFlush();
			New = false;
		}

		public override void Save()
		{
			base.Save();
			New = false;
		}

		public override void Delete()
		{
			if (!New)
			{
				base.Delete();
			}
		}

		public override void DeleteAndFlush()
		{
			if (!New)
			{
				base.DeleteAndFlush();
			}
		}

		public override string ToString()
		{
			return (SpellId)_spellId + " (" + SpellId + ")";
		}
	}
}
